/*
 * @Author: 肖思汗 
 * @Date: 2025-06-25 22:50:54 
 * @Last Modified by: 肖思汗
 * @Last Modified time: 2025-06-25 22:54:11
 */

import Taro from "@tarojs/taro";

class FileCache {

    constructor() { }


    async get(url: string) {

        const fileUrl = Taro.getStorageSync(url);
        if (fileUrl) {
            return fileUrl;
        }

        const res = await Taro.downloadFile({
            url: url,
            success: (res) => {
                console.log("下载成功", res);
                Taro.setStorageSync(url, res.tempFilePath);
            },
            fail: (res) => {
                console.log("下载失败", res);
            }
        });
        
        return res.tempFilePath;
    }

}

const fileCache = new FileCache();

export default fileCache;

